<?php
namespace app\admin\controller;
use app\common\controller\Common;
use app\admin\model\GoodsModel;
use app\common\model\Category;
use app\common\model\Shop;
use think\Exception;
use think\Request;
class Goods extends Common
{
	/**
    * 产品管理
    */
    public function goods()
    {
        if(request()->isPost())
		{
			$info = Request::instance()->param();
			return GoodsModel::getGoods($info);
		}

        $this->assign('shop',(new Shop())->shopList(['is_show'=>0],'shop_id,shop_name'));
        return $this->fetch();
    }
    /**
    * 产品库存
    */
    public function goodslist()
    {
        if(request()->isPost())
		{
			$info = Request::instance()->param();
			return GoodsModel::goodsList($info);
		}
       $this->assign('fcat',(new Category())->categoryList(['fid'=>0],'category_id,category_name'));
       return $this->fetch();  
    }
    /**
    * 库存详情
    */
    public function stocklist()
    {
        $info = Request::instance()->param();
        if(request()->isPost())
		{
			return GoodsModel::getStockList($info);
		}

        $this->assign('shop',(new Shop())->shopList(['is_show'=>0],'shop_id,shop_name'));
        $this->assign('goods_id',$info['id']);
        $goodsinfo = GoodsModel::goodsinformation($info['id']);
        $this->assign('goodsinfo',$goodsinfo);
        return $this->fetch();
    }
    /**
    * 门店入库
    */
    public function stockgoodslist()
    {
        if(request()->isPost())
		{
			$info = Request::instance()->param();
			return GoodsModel::stockGoodsList($info);
		}

        $this->assign('shop',(new Shop())->shopList(['is_show'=>0],'shop_id,shop_name'));
        $this->assign('fcat',(new Category())->categoryList(['fid'=>0],'category_id,category_name'));
		return $this->fetch();
    }
    /**
    * 门店入库 详情
    */
    public function stockgoodsinfo()
    {
        $info = Request::instance()->param();
        $stockGoodsInfo = GoodsModel::stockGoodsInfo($info);
        $this->assign('info',$stockGoodsInfo);
        return $this->fetch();
    }
    /**
    * 商品库存信息
    */
    public function gstocklist()
    {
        if(request()->isPost())
		{
			try{
				$info = Request::instance()->param();
				return json(GoodsModel::gstockList($info));
			}catch (\Exception $e){
				return json(back(config('state.STATUS_CODE_FOURONE'),$e->getMessage()));
			}
		}
    }
    /**
    * 过期产品
    */
    public function overdue()
    {
        if(request()->isPost())
		{
			$info = Request::instance()->param();
			return GoodsModel::overdue($info);
		}
        $this->assign('shop',(new Shop())->shopList(['is_show'=>0],'shop_id,shop_name'));
        $this->assign('fcat',(new Category())->categoryList(['fid'=>0],'category_id,category_name'));
		return $this->fetch();
    }
    /**
    * 退货召回库存
    */
    public function stockafter()
    {
        if(request()->isPost())
		{
			$info = Request::instance()->param();
			return GoodsModel::stockLossList($info);
		}
        $this->assign('shop',(new Shop())->shopList(['is_show'=>0],'shop_id,shop_name'));
        $this->assign('supp',(new Supplier())->supplierList(['is_show'=>0],'supplier_id,supplier_name'));
        $this->assign('fcat',(new Category())->categoryList(['fid'=>0],'category_id,category_name'));
        return $this->fetch();
    }
    /**
    * 确认退货
    */
    public function recovery()
    {
        if(request()->isPost())
		{
			try{
				$info = Request::instance()->param();
				return GoodsModel::recoveryStock($info);
			}catch (\Exception $e){
				return json(back(config('state.STATUS_CODE_FOURONE'),$e->getMessage()));
			}
		}
    }
    /**
    * 返回门店
    */
    public function returnstock()
    {
        if(request()->isPost())
		{
			try{
				$info = Request::instance()->param();
				return GoodsModel::returnStock($info);
			}catch (\Exception $e){
				return json(back(config('state.STATUS_CODE_FOURONE'),$e->getMessage()));
			}
		}
    }
    /**
    * 报损库存
    */
    public function stocklosslist()
    {
        if(request()->isPost())
		{
			$info = Request::instance()->param();
			return GoodsModel::stockLossList1($info);
		}
		$this->assign('fcat',(new Category())->categoryList(['fid'=>0],'category_id,category_name'));
        $this->assign('shop',(new Shop())->shopList(['is_show'=>0],'shop_id,shop_name'));
		return $this->fetch();
    }
    /**
    * 产品历史记录
    */
    public function historygoods()
    {
        if(request()->isPost())
		{
			$info = Request::instance()->param();
			return GoodsModel::historyGoods($info);
		}
        $this->assign('fcat',(new Category())->categoryList(['fid'=>0],'category_id,category_name'));
        $this->assign('shop',(new Shop())->shopList(['is_show'=>0],'shop_id,shop_name'));
        return $this->fetch();
    }
}